<?php 
$show_validator = true; 
include TMPL_PATH.'public/header.phtml';
?>
<style type='text/css'>
.pic {
    float: left;
    margin-right: 10px;
    text-align: center;
}
.pic img {
    border: 3px solid #EFEFED;
    cursor: pointer;
}
.pic img.current {
    border: 3px solid #FF6600;
}
</style>
<script type='text/javascript' src="/statics/js/swfupload/swfupload.js"></script>
<script type='text/javascript' src="/statics/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="/statics/js/swfupload/fileprogress.js"></script>
<script type="text/javascript" src="/statics/js/swfupload/handlers.js"></script>
<script type="text/javascript"> 
<!--
	$(function(){
		$.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'200',height:'50'}, function(){this.close();$(obj).focus();})}});
		$("#description").formValidator({onshow:"请填写审核备注",onfocus:"请填写审核备注",oncorrect:"输入正确"}).inputValidator({min:2,onerror:"请填写审核备注"});
	})
//-->
</script>
<div class="subnav">
    <div class="content-menu ib-a blue line-x">
    		<a href='<?php echo U('comment/index');?>' ><em>评论列表</em></a><span>|</span>
        <a href='javascript:;' class="on" ><em>评论回复</em></a></div>
</div>
<div class="pad_10">
<div class="col-tab">
<!--	<ul class="tabBut cu-li">-->
<!--	<li id="tab_setting_1" class="on" onclick="SwapTab('setting','on','',2,1);">评论信息</li>-->
<!--	<li id="tab_setting_2" onclick="SwapTab('setting','on','',2,2);">反馈信息</li>-->
<!--	</ul>-->
	<form action="__SELF__" method="post" id="myform">
	<div id="div_setting_1" class="contentList pad-10">
		<table width="100%" class="table_form contentWrap">
		<tr>
		<td width="80">产品id</td> 
		<td><input name="product_id" value="<?php echo $comment['product_id'];?>" /></td>
		</tr>			
		<tr>
		<td>评论人邮箱</td>
		<td><input name="email" value="<?php echo $comment['email'];?>" /></td>
		</tr>
		<tr>
		<td>评论内容</td>
		<td><textarea name="content" style="width:400px;height:150px;"><?php echo $comment['content'];?></textarea></td>
		</tr>
		<tr>
		<td>评论星级</td>
		<td><select name="star">
			    <?php for($i=5;$i>0;$i--){?>
			    <option value="<?php echo $i;?>" <?php echo $comment['star'] == $i ? 'selected' : '';?>><?php echo $i;?></option>
			    <?php }?>
		    </select>
	    </td>
		</tr>
		<tr>
		<td>评论状态</td>
		<td>
        <input type="radio" name="disabled" value="0" <?php echo !$comment['disabled'] ? 'checked' : '';?>/>隐藏 
        <input type="radio" name="disabled" value="1" <?php echo $comment['disabled'] ? 'checked' : '';?> />显示
        </td>
		</tr>
        <tr>
        <td>产品相册：</td>
        <td>
        <input type="hidden" name="photo_name" id="photo_name" value=""/>
        <input type="hidden" name="focus_photo" id="focus_photo" value="<?php echo $comment['img'] ? $comment['img'] : null;?>"/>
        <input type="hidden" name="small_img" id="small_img" value="<?php echo $comment['small_img'] ? $comment['small_img'] : null;?>"/>
        <input type="hidden" name="thumb" id="thumb" value=""/>
        <input type="hidden" name="upimage" value="" />
        <input type="hidden" name="del_photo_name" id="del_photo_name" value=""/>
        <div class="upload_btn"><span id="upload"></span></div><label style="margin-left:20px">可以上传多张图片，上传默认第一张为产品图片，点击选择其他图片</label></td>
        </tr>
		<tr>
	    <td></td><td id="show"></td>
		</tr>
		<tr>
			<td></td>
			<td id="show_list">
			<?php 
				if($comment_photo):
					foreach ($comment_photo as $key=>$file):
			?>
						<span id="a<?php echo $file['fid'];?>" class="pic">
								<img name="img_name" <?php if(strpos($comment['img'],$file['img'])!==false){?>class="current"<?php }?> style="margin: 5px; opacity: 1;" src="<?php echo $file['thumb']?>" onclick="focus_img('<?php echo $file['img'];?>',this)"  <?php if($file['img'] == $product['img']):?>class="current"<?php endif;?> />
								<br>
								<a id="<?php echo $file['fid'];?>" href="javascript:;" onclick="del_img(this.id)">删除</a>
							</span>
			<?php 
					endforeach;
				endif;
			?>
			</td>
		</tr>        
		</table>
	</div>
	<div id="div_setting_2" class="contentList pad-10">
	  </table>
	  <div class="bk15"></div> 
	  <input name="dosubmit" type="submit" value="提交" class="button">
	</div>
    </form>
</div>
</div>
</body>
</html>
<script type="text/javascript">
var swfu;
window.onload = function () {
	swfu = new SWFUpload({
		// Backend Settings
		upload_url: "<?php echo U('product/swfupload_ajax',array('type'=>'comment'));?>",
		post_params: {"PHPSESSID": "<?php echo session_id();?>"},

		file_size_limit : "2 MB",	// 2MB
		file_types : "*.jpg;*.jpge;*.png;*.gif",
		file_types_description : "JPG Images",
		file_upload_limit : "5",
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,

		// Button Settings
		button_placeholder_id : "upload",
		button_width: 50,
		button_height: 21,
		button_text : '浏览...',
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,

		// Flash Settings
		flash_url : "/statics/js/swfupload/swfupload.swf",

		custom_settings : {
			upload_target : "show"
		},
		// Debug Settings
		debug: false
	});
};
function show_link(img)
{
	window.top.art.dialog({title:'图片链接', id:'link', iframe:'<?php echo U('product/public_show_photo_link_ajax');?>&img='+img,width:'600px',height:'200px'},function(){window.top.art.dialog({id:'link'}).close()});
}
function del_img(id)
{
	$('#del_photo_name').val($('#del_photo_name').val()+id+',')
	//删除数组元素.
	Array.prototype.remove=function(dx)
	{
	    if(isNaN(dx)||dx>this.length){return false;}
	    for(var i=0,n=0;i<this.length;i++)
	    {
	        if(this[i]!=this[dx])
	        {
	            this[n++]=this[i]
	        }
	    }
	    this.length-=1
	}
	//在数组中获取指定值的元素索引
	Array.prototype.getIndexByValue= function(value)
	{
	    var index = -1;
	    for (var i = 0; i < this.length; i++)
	    {
	        if (this[i] == value)
	        {
	            index = i;
	            break;
	        }
	    }
	    return index;
	}
	var photo_name = $('#photo_name').val();
	photo_name = photo_name.substring(0,photo_name.length-1);
	var arr = photo_name.split(',');
	var key = 0;
	for(var i=0;i<arr.length;i++){
		if(arr[i].indexOf(id)>-1){
			key = i;
		}
	}
	arr.remove(key);
	if(arr.length>0)
	{
		//如果没有全部删除则不为空
		$('#photo_name').val(arr.join(',')+',');
		$("#a"+id).remove();
		var focus_photo = $('#focus_photo').val();
		var is_curr = 0;//是否为选择图片
		$('#show_list > .pic > img').each(function(index){
			if($(this).hasClass('current')){
				is_curr=1;
			}
		});
		
		if(is_curr==1) return true;
		//重新选择第一个为默认图片
		curr_new_id = arr[0];

		var obj_curr_img = $("#a"+curr_new_id+'>img');
		obj_curr_img.addClass('current');
		$('#small_img').val(obj_curr_img.attr('src'));
		//$('#focus_photo').val(obj_curr_img.attr('original'));
		obj_curr_img.click();
	}else{
		//如果图片全部删除则值为空
		$('#photo_name').val("");
		$('#focus_photo').val("");
		$('#small_img').val("");
		$("#a"+id).remove();
	}
}
function focus_img(little,obj)
{
	window.open(little);
/*	$('#focus_photo').val(little);
	$("img[name='img_name']").removeClass('current');
	obj.className = 'current';*/
}
</script>